/*
defer
liuyang:貌似就是Spring的@RunAfterReturn
https://www.bilibili.com/video/BV1gf4y1r79E/?p=11&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
*/
package main

import "fmt"

// 注意调用顺序
func foo() {
	fmt.Println("c foo")
}

// defer vs return
func returnAndDefer() string {
	defer fmt.Println("defer in returnAndDefer") // 看来是在return后执行的！
	return funcCalledAtReturn()
}

func funcCalledAtReturn() string {
	fmt.Println("funcCalledAtReturn!!")
	return "funcCalledAtReturn!!!"
}

func main() {
	defer fmt.Println("a hello, defer")
	defer fmt.Println("b main end")
	defer foo()

	fmt.Println("main")

	// defer vs return
	ret1 := returnAndDefer()
	fmt.Println("returnAndDefer return = ", ret1)
}
